package me.mcx.mcx.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import me.mcx.common.utils.DateUtils;
import lombok.extern.slf4j.Slf4j;
import me.mcx.mcx.domain.McxWebConfig;
import me.mcx.mcx.mapper.McxWebConfigMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import me.mcx.mcx.service.IMcxWebConfigService;

/**
 * 网站配置Service业务层处理
 * 
 * @author mcx
 * @date 2024-09-21
 */
@Service
@Slf4j
public class McxWebConfigServiceImpl implements IMcxWebConfigService 
{
    @Autowired
    private McxWebConfigMapper mcxWebConfigMapper;

    /**
     * 查询网站配置
     * 
     * @param id 网站配置主键
     * @return 网站配置
     */
    @Override
    public McxWebConfig selectMcxWebConfigById(Long id)
    {
        return mcxWebConfigMapper.selectMcxWebConfigById(id);
    }

    /**
     * 查询网站配置列表
     * 
     * @param mcxWebConfig 网站配置
     * @return 网站配置
     */
    @Override
    public List<McxWebConfig> selectMcxWebConfigList(McxWebConfig mcxWebConfig)
    {
        return mcxWebConfigMapper.selectMcxWebConfigList(mcxWebConfig);
    }

    /**
     * 新增网站配置
     * 
     * @param mcxWebConfig 网站配置
     * @return 结果
     */
    @Override
    public int insertMcxWebConfig(McxWebConfig mcxWebConfig)
    {
        mcxWebConfig.setCreateTime(DateUtils.getNowDate());
        return mcxWebConfigMapper.insertMcxWebConfig(mcxWebConfig);
    }

    /**
     * 修改网站配置
     * 
     * @param mcxWebConfig 网站配置
     * @return 结果
     */
    @Override
    public int updateMcxWebConfig(McxWebConfig mcxWebConfig)
    {
        mcxWebConfig.setUpdateTime(DateUtils.getNowDate());
        return mcxWebConfigMapper.updateMcxWebConfig(mcxWebConfig);
    }

    /**
     * 批量删除网站配置
     * 
     * @param ids 需要删除的网站配置主键
     * @return 结果
     */
    @Override
    public int deleteMcxWebConfigByIds(Long[] ids)
    {
        return mcxWebConfigMapper.deleteMcxWebConfigByIds(ids);
    }

    /**
     * 删除网站配置信息
     * 
     * @param id 网站配置主键
     * @return 结果
     */
    @Override
    public int deleteMcxWebConfigById(Long id)
    {
        return mcxWebConfigMapper.deleteMcxWebConfigById(id);
    }

    @Override
    public Map<String, Object> selectMcxWebConfigDict(List<String> titleList) {
        Map<String, Object> webConfigDict = new HashMap<>();
        List<McxWebConfig> webConfigList = mcxWebConfigMapper.selectMcxWebConfig(titleList);
        for (int i = 0; i < webConfigList.size(); i++) {
            webConfigDict.put(webConfigList.get(i).getTitle(), webConfigList.get(i).getContent());
        }
        return webConfigDict;
    }
}
